package com.hc.security;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Bean
    public PasswordEncoder passwordEncoder() {
        //使用SpringSecurity自带的加解密算法
        return new BCryptPasswordEncoder();
    }

    //@Resource
    //private MyUserDetailsService myUserDetailsService;
    //@Override
    //protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    //    auth.userDetailsService(myUserDetailsService);
    //}
    //
    //@Override
    //public void configure(WebSecurity web) throws Exception {
    //    web.ignoring().antMatchers("/static/**");
    //}

    //@Override
    //protected void configure(HttpSecurity http) throws Exception {
        //http.formLogin() //表示是表单提交
        //        .loginPage("/toLogin") //设置登录页面对应的地址，默认是/login
        //        .loginProcessingUrl("/fun") //设置用户登录逻辑的请求地址，默认是/login
        //;
        ////授权
        //http.authorizeRequests()
        //        .antMatchers("login").permitAll()//toLogin不需要拦截，可以随便访问
        //        .anyRequest().authenticated()//所有的请求都必须认证后才能访问
        //;
        ////为了保证完整流程可用关闭CSRF安全协议
        //http.csrf().disable();
    //}

}

